home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Trees / RedBlackTreeLoop.h < prev    next >
Encoding:
Text File  |  1997-06-28  |  2.9 KB  |  83 lines  |  [TEXT/CWIE]

  1. // RedBlackTreeLoop.h
  2.  
  3. #ifndef RedBlackTreeLoop_h
  4. #define RedBlackTreeLoop_h
  5.  
  6. #ifndef RedBlackNode_h
  7. #include "RedBlackNode.h"
  8. #endif
  9. #ifndef RedBlackTree_h
  10. #include "RedBlackTree.h"
  11. #endif
  12. #ifndef TreeLoop_h
  13. #include "TreeLoop.h"
  14. #endif
  15.  
  16. template < class Key, class Target >
  17. class RedBlackTreeLoop: private TreeLoop
  18.   {
  19.     typedef RedBlackNode<Key,Target> LinkType;
  20.     typedef RedBlackTree<Key,Target> HeadType;
  21.     typedef RedBlackTreeLoop<Key,Target> LoopType;
  22.     typedef TreeLoop Inherited;
  23.     
  24.     private:
  25.         static const LinkType *DownCast( const TreeNode *n )
  26.           {
  27.             return static_cast< const LinkType* >( n );
  28.           }
  29.  
  30.         static const HeadType& DownCast( const Tree& n )
  31.           {
  32.             return static_cast< const HeadType& >( n );
  33.           }
  34.         
  35.     public:
  36.         RedBlackTreeLoop( const HeadType& h )                                        : Inherited( h )                    {}
  37.         RedBlackTreeLoop( const HeadType& h, AtStart )                            : Inherited( h, atStart )        {}
  38.         RedBlackTreeLoop( const HeadType& h, AtEnd )                                : Inherited( h, atEnd )            {}
  39.         RedBlackTreeLoop( const HeadType& h, Nowhere )                            : Inherited( h, nowhere )        {}
  40.         RedBlackTreeLoop( const HeadType& h, const LinkType& p )                : Inherited( h, p )                {}
  41.         RedBlackTreeLoop( const HeadType& h, Before, const LinkType& p )    : Inherited( h, before, p )    {}
  42.         RedBlackTreeLoop( const HeadType& h, After, const LinkType& p )    : Inherited( h, after, p )        {}
  43.         RedBlackTreeLoop( const HeadType& h, BeforeStart )                        : Inherited( h, beforeStart )    {}
  44.         RedBlackTreeLoop( const HeadType& h, AfterEnd )                            : Inherited( h, afterEnd )        {}
  45.  
  46.         const HeadType& Owner() const                        { return DownCast( Inherited::Owner() ); }
  47.         
  48.         Inherited::Finished;
  49.         Inherited::Unfinished;
  50.  
  51.         Inherited::MoveToFinish;
  52.         Inherited::MoveToFirst;
  53.         Inherited::MoveToLast;
  54.         Inherited::MoveBeforeFirst;
  55.         Inherited::MoveAfterLast;
  56.         
  57.         void MoveTo( const LinkType& p )                    { Inherited::MoveTo( p ); }
  58.         void MoveBefore( const LinkType& p )            { Inherited::MoveBefore( p ); }
  59.         void MoveAfter( const LinkType& p )                { Inherited::MoveAfter( p ); }
  60.                     
  61.         bool operator==( const LoopType& r ) const    { return Inherited::operator==( r ); }
  62.         bool operator!=( const LoopType& r ) const    { return Inherited::operator!=( r ); }
  63.  
  64.         bool operator==( const LinkType& r ) const    { return Inherited::operator==( r ); }
  65.         bool operator!=( const LinkType& r ) const    { return Inherited::operator!=( r ); }
  66.             
  67.         Inherited::Null;
  68.         const LinkType *Position() const        { return DownCast( Inherited::Position() ); }
  69.         
  70.         const LinkType *Next() const            { return DownCast( Inherited::Next() ); }
  71.         const LinkType *Previous() const        { return DownCast( Inherited::Previous() ); }
  72.         
  73.         Target& operator*() const        { return **DownCast( Inherited::operator->() ); }
  74.         Target *operator->() const        { return &**DownCast( Inherited::operator->() ); }
  75.         
  76.         void operator++()                            { Inherited::operator++(); }
  77.         void operator++(int)                        { Inherited::operator++(0); }
  78.         void operator--()                            { Inherited::operator--(); }
  79.         void operator--(int)                        { Inherited::operator--(0); }
  80.   };
  81.  
  82. #endif
  83.